//引入模块
const http = require("http");
// const url = require("url");

http.createServer(function (request, response) {
    response.writeHead(200, {"Content-Type": "text/html;charset=UTF-8"});

    if (request.url !== "/favicon.ico") {
        console.log(request.headers.host + request.url);

        /*url.parse()接口失效不再使用
        let result = url.parse(request.url, true); //获取url信息，第二参数为true是将get参数值序列化成对象
        console.log(result.query);*/

        let myURL = new URL(request.url, "http://" + request.headers.host);
        console.log(myURL.searchParams);
        console.log(myURL.searchParams.get("name"));
    }

    response.write("Hello World !!!");
    response.write("这是第一个nodejs程序！！！");
    response.end(); //不加此行浏览器会一直加载

}).listen(8080); //监听的端口

console.log("nodejs 8080 port is starting...");